package com.forchange.exe1

import org.apache.spark.{SparkConf, SparkContext}

object Sprak_WordCount1 {
  def main(args: Array[String]): Unit = {
    //1 创建spark的环境
    val sparkConf = new SparkConf().setMaster("local").setAppName("WordCount")
    //2 连接spark
    val scc = new SparkContext(sparkConf)
    //3 具体的逻辑
    val datas = scc.textFile("/Users/chencong/Desktop/spark_learning/input/WordCount")
    val wordcount= datas.
      flatMap(_.split(","))
      .map((_, 1))
      .reduceByKey(_ + _)
//    print(wordcount.collect().mkString(","))
      wordcount.saveAsTextFile("output")
    //4 关闭连接
    scc.stop()

  }

}
